<% layout('/layouts/default.html', {title: '售后订单管理', libs: ['dataGrid']}){ %>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-notebook"></i> ${text('售后订单管理')}
            </div>
            <div class="box-tools pull-right">
                <a href="javascript:void(0);" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
            </div>
        </div>
        <div class="box-body">
            <#form:form id="searchForm" model="${order}" action="${ctx}/storage/order/serviceData" method="post" class="form-inline hide"
                    data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
                <div class="form-group">
                    <label class="control-label">${text('状态')}：</label>
                    <div class="control-inline" style="width: 120px;">
                        <% var statusList = [{status:'待处理'},{status:'处理中'},{status:'成功退款'},{status:'已拒绝'}]; %>
                        <#form:select path="serviceStatus" class="form-control" items="${statusList}" itemLabel="status" itemValue="status" blankOption="true" blankOptionLabel="请选择"/>
                    </div>
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
                    <button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
                </div>
            </#form:form>
            <table id="dataGrid"></table>
            <div id="dataGridPage"></div>
        </div>
    </div>
</div>
<% } %>
<script>
var dataList = [];
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
    searchForm: $("#searchForm"),
    columnModel: [
        {header:'${text("发起时间")}', name:'serviceDate', index:'a.serviceDate', width:150, align:"center"},
        {header:'${text("用户")}', name:'nickName', index:'a.nickName', width:150},
        {header:'${text("总金额")}', name:'serviceAmount', index:'a.serviceAmount', width:150, align:"center",formatter: function(val, obj, row, act){
            return '￥' + val;
        }},
        {header:'${text("数量")}', name:'serviceNum', index:'a.serviceNum', width:150, align:"center"},
        {header:'${text("申请类型")}', name:'serviceType', index:'a.serviceType', width:150, align:"center"},
        {header:'${text("申请原因")}', name:'serviceReason', index:'a.serviceReason', width:150, align:"center"},
        {header:'${text("状态")}', name:'serviceStatus', index:'a.serviceStatus', width:150, align:"center"},
        {header:'${text("操作")}', width:120, align:"center", sortable:false, title:false, formatter: function(val, obj, row, act){
            var actions = [];
            if(row.sysAduitStatus === '待审核'){
                actions.push('<a href="${ctx}/storage/order/service/agree?orderId='+row.orderId+'" class="btnList" title="${text("同意退款申请")}" data-confirm="${text("确认同意退款申请吗？")}"><i class="icon-check"></i>同意申请</a>&nbsp;');
                actions.push('<a href="javascript:void(0);" onclick="doReject('+row.orderId+')" title="${text("拒绝退款申请")}"><i class="icon-close"></i>拒绝申请</a>&nbsp;');
            }
            if(row.serviceStatus === '待退货入库'){
                actions.push('<a href="${ctx}/storage/order/service/signed?orderId='+row.orderId+'" class="btnList" title="${text("收到退货")}" data-confirm="${text("确认收到退货吗？")}"><i class="icon-check"></i>收到退货</a>&nbsp;');
            }
            return actions.join('');
        }}
    ],
    subGrid: true,  // (1)开启子表格支持
    subGridRowExpanded: function(subgrid_id, row_id){
        console.log(subgrid_id);
        console.log(row_id);
        console.log(dataList[row_id - 1]);
        $("#" + subgrid_id).html("<table id='"+subgrid_id+"DataGrid'></table>");
        $('#'+subgrid_id+'DataGrid').dataGrid({
            data: dataList[row_id - 1].orderGoodsList,
            datatype: "local", // 设置本地数据
            height:'auto',
            columnModel: [
                {header:'${text("商品")}', name:'goodsName', index:'a.goodsName'},
                {header:'${text("尺码")}', name:'goodsSpecName', index:'a.goodsSpecName'},
                {header:'${text("单价")}', name:'salePrice', index:'a.salePrice', width:90, align:"center",formatter: function(val, obj, row, act){
                    return '￥' + val;
                }},
                {header:'${text("数量")}', name:'serviceNum', index:'a.serviceNum', width:90, align:"center"},
                {header:'${text("总金额")}', name:'serviceAmount', index:'a.serviceAmount', width:90, align:"center",formatter: function(val, obj, row, act){
                    return '￥' + val;
                }},
            ]
        });
    },
    ajaxSuccess: function(data){
        dataList = data.list;
        console.log(data);
    }
});
</script>
<script>
    function doReject(orderId) {
        js.layer.open({
            type: 1,
            area: ['600px'],
            title: '${text("拒绝退款申请")}',
            resize: false,
            scrollbar: true,
            content: js.template('rejectTpl'),
            btn: ['<i class="fa fa-check"></i> ${text("拒绝")}',
                '<i class="fa fa-remove"></i> ${text("关闭")}'],
            btn1: function(index, layero){
                js.ajaxSubmit("${ctx}/storage/order/service/reject",{
                    orderId:orderId,
                    reason: layero.find('#reason').val(),
                }, function(data){
                    js.showMessage(data.message);
                    if(data.result == Global.TRUE){
                        window.location.reload();
                    }
                    page();
                }, "json");
                return true;
            }
        });
    }
</script>
<script id="rejectTpl" type="text/template">
    <div class="row" style="margin: 30px auto;">
        <div class="col-xs-12">
            <div class="form-group">
                <label class="control-label col-sm-2" title="">
                    <span class="required ">*</span>${text('原因')}：<i class="fa icon-question hide"></i></label>
                <div class="col-sm-10">
                    <#form:textarea id="reason" name="reason" rows="4" maxlength="255" class="form-control"/>
                </div>
            </div>
        </div>
    </div>
</script>